<template>
	<view class="hui">
        <!-- <u-navbar title=" " >
			 <u-search @click="toSearch" placeholder-color="#C2C1C7" search-icon-color="#C2C1C9" bg-color="#F2F1F6" shape="square" :show-action="false" placeholder="请搜索您需要的服务" disabled></u-search>
		 </u-navbar> -->
		<view class="k_box">
			
				<scroll-view :scroll-with-animation="true" class='keyword_box' :scroll-x="true" show-scrollbar="false">
					<view :class="['keyword']" @click="setOneCheck(item)"
						v-for="(item,index) in oneCate" :key="index">
							<image :class="['key_img',oneCheck.id==item.id?'img_check':'']" :src="item.image"></image>
						<view :class="[oneCheck.id==item.id?'name_check':'']">
							{{item.name}}
						</view>
					</view>
				</scroll-view>
		
		</view>

		<view class="flex">
			<scroll-view class="left" :scroll-y="true" :show-scrollbar="false">
				<view @click="setCateCheck(item)" :class="['cate',item.id==cateCheck.id?'cate_check':'']"
					v-for="(item,index) in cate" :key="index">
					{{item.name}}
				</view>
			</scroll-view>

			<view class="right_box">
				<!-- <view class="rhead">
					<scroll-view  :scroll-left="scrollLeft" :scroll-with-animation="true" class="rsroll" :scroll-x="true" :show-scrollbar="false">
						<view @click="setChildCate(item,index)" :class="['childcate',item.id==childcateCheck.id?'childcate_check':'']"
							v-for="(item,index) in childcate" :key="index">
							{{item.name}}
						</view>
					</scroll-view>
					<view class="rxia" @click="show=true">
						<view class="rixa_down">
							<u-icon name="arrow-down" color="#6C6C6C" size="28"></u-icon>
						</view>
					</view>
				</view>
				<view style="height: 50px;"></view> -->

				<scroll-view :scroll-top="scrollTop" :scroll-with-animation="true" :scroll-y="true"
					:show-scrollbar="false" class="list_box">
					<view class="list">

						<view v-for="(item,index) in childcate" :key="index">
							<view class="name_box">
								<view class="name">{{item.name}}</view>
							</view>
							<view class="icon_box">
								<view @click="toFw(items)" class="icon_info"
									v-for="(items,indexs) in item.children" :key="indexs">
									<image mode="widthFix" :src="items.image"></image>
									<view class="icon_name">{{items.name}}</view>
								</view>
							</view>
						</view>

					</view>
				</scroll-view>


			</view>

		</view>


		<u-popup v-model="show" mode="top" border-radius="14">
			<view class="top_box">
				<view class="t_head">
					<view>{{cateCheck.name}}</view>
					<u-icon name="arrow-up" color="#6E6E6E" size="22"></u-icon>
				</view>
				<view class="icon_box">
					<view @click="setChildCate(item,index)"
						:class="['top_info',item.id==childcateCheck.id?'top_check':'']"
						v-for="(item,index) in childcate" :key="index">
						{{item.name}}
					</view>
				</view>
			</view>
		</u-popup>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				cate_id: '',
				oneCate:[],
				oneCheck:{id:0},
				cateCheck: {
					id: 0
				},
				cate: [],
				childcateCheck: {
					id: 0
				},
				childcate: [],
				show: false,
				scrollLeft: 0,
				scrollTop: 0
			}
		},
		onLoad(e) {
			if (e.cate_id) {
				this.cate_id = e.cate_id;
			}
			this.getCate();
		},
		methods: {
			toFw(e){
				uni.navigateTo({
					url:'/pages/fw/info?id='+e.id
				})
			},
			toSearch() {
				
					uni.navigateTo({
						url: '/pages/index/search?type=2'
					})
					return;
				
				uni.navigateTo({
					url: '/pages/index/search?type=2&cate_id='+es.id+'&pid='+e.id
				})
			},
			setChildCate(item, e) {
				this.show = false;
				let width = 0;
				let top = 0;
				this.childcateCheck = item;
				this.childcate.forEach((res, index) => {

					if (index >= e) return;
					width += res.name.length * 15 + 10;
					top += Math.ceil(res.children.length / 3) * 71.33 + 57;
				});



				console.log(width);

				this.scrollLeft = width;
				this.scrollTop = top;
			},
			setCateCheck(e) {
				this.cateCheck = e;
				this.scrollLeft = 0;
				this.scrollTop = 0;
				this.getChildCate();
			},
			setOneCheck(e){
				this.oneCheck=e;
				this.getTwoCate();
			},
			getChildCate() {
				let parm = {
					cate_id: this.cateCheck.id
				};
				this.$get(this.$api.fwchildcate, parm, res => {
					let data = res.data;
					if (data.code == 1) {
						this.childcate = data.data;
						if (data.data && data.data.length > 0) {
							this.childcateCheck = data.data[0];
						}
					}
				});
			},
			getTwoCate(){
				this.$get(this.$api.fwcate, {pid:this.oneCheck.id}, res => {
					let data = res.data;
					if (data.code == 1) {
						this.cate = data.data;
						if (data.data && data.data.length > 0) {
				
				
								this.cateCheck = data.data[0];
							
				
							this.getChildCate();
						}
					}
				})
			},
			getCate() {
				this.$get(this.$api.fwcate, {}, res => {
					let data = res.data;
					if (data.code == 1) {
						this.cate = data.data;
						if (data.data && data.data.length > 0) {
							
							    if(this.cate_id){
									
									data.data.forEach(res=>{
										
										if(res.id==this.cate_id){
											this.oneCheck=res;
										}
										
									});
									
								}else{
									this.oneCheck=data.data[0];
								}
							    
								
								this.oneCate=data.data;
							    this.getTwoCate();							
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	scroll-view ::-webkit-scrollbar {
		display: none;
		width: 0;
		height: 0;
		color: transparent;
	}


.k_box{
		width: 100%;
		background-color: white;
		font-size: 26rpx;
		color: #8D8D8D;
		border-bottom: 4rpx solid #F1F1F1;
		box-sizing: border-box;
		padding: 10rpx 0 25rpx 0;
	}
	.keyword_box{
		box-sizing: border-box;
		padding: 0rpx 0rpx 0 0rpx;
		width: 100%;
		white-space: nowrap;
		
	}
	.key_img{
		width: 80rpx;
		height: 80rpx;
		border-radius:30rpx;
	}
	.keyword {
		display: inline-block;
		text-align: center;
		height: 100%;
		margin-left: 50rpx;
	}
	.keywords {
		width: 20%;
		display: inline-block;
		//margin: 0 20rpx 0 0;
		text-align: center;
		height: 100%;
		box-sizing: border-box;
		padding: 10rpx 0 35rpx 0;
	}
	
	.img_check{
		border: 4rpx solid #EB7D62;
	}
	.name_check{
		color: black;
	    font-weight: bold;
	}



	.hui {
		background-color: #F2F1F6;
		min-height: 100vh;
	}

	.flex {
		display: flex;
		align-items: center;
	}

	.left {
		height: calc(100vh - 152px);
		width: 25%;
		text-align: center;
		background-color: #F2F1F6;
	}

	.right_box {
		height: calc(100vh - 152px);
		width: 75%;
		background-color: #F4F4F4;
		position: relative;
		border-radius: 25rpx;
	}

	.cate {
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
		color: #737373;
		font-size: 28rpx;
	}

	.cate_check {
		font-weight: bold;
		font-size: 30rpx;
		color: black;
		background-color: white;
		position: relative;
	}

	.cate_check:before {
		content: '';
		background: #ED4338;
		width: 6rpx;
		height: 40rpx;
		position: absolute;
		left: 0;
		top: 27rpx;
	}

	.rhead {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		display: flex;
		align-items: center;
		height: 100rpx;
		background-color: #F4F4F4;
	}

	.rxia {
		width: 15%;
		height: 100%;
		background-color: #F4F4F4;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.rixa_down {
		width: 56rpx;
		height: 56rpx;
		line-height: 56rpx;
		border-radius: 50%;
		background-color: white;
		text-align: center;

	}

	.rsroll {
		width: 85%;
		display: flex;
		align-items: center;
		background-color: #F4F4F4;
		box-sizing: border-box;
		//padding: 0 0 20rpx 0;
		white-space: nowrap;
	}

	.childcate {
		display: inline-block;
		background-color: white;
		box-sizing: border-box;
		padding: 10rpx 25rpx;
		color: black;
		border-radius: 35rpx;
		font-size: 26rpx;
		margin-right: 20rpx;
	}

	.childcate_check {
		background-color: #FEE9E8;
		border: 1rpx solid #f44b44;
		color: #f44b44;
		padding: 9rpx 25rpx;
	}

	.name_box {
		padding-top: 25rpx;
		margin-left: 25rpx;
		display: flex;
		align-items: center;
	}

	.name {
		font-weight: bold;
		font-size: 26rpx;
		color: black;
		margin-right: 15rpx;
	}

	.list_box {

		height:100%;
	}

	.list {

		background-color: white;
		min-height: 100%;
		box-sizing: border-box;
		padding-bottom: 25rpx;
	}

	.icon_box {
		display: flex;
		align-items: center;
		flex-wrap: wrap;
	}

	.icon_info {
		width: 28%;
		margin-top: 25rpx;
		margin-left: 25rpx;

		image {
			width: 95%;
			height: 100rpx;
			border-radius: 15rpx;
		}
	}

	.icon_name {
		color: #363638;
		font-size: 26rpx;
	}

	.top_box {
		box-sizing: border-box;
		padding: 25rpx 0 25rpx 20rpx;
		background-color: #F6F6F6;
	}

	.t_head {
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-weight: bold;
		color: black;
		box-sizing: border-box;
		padding-right: 20rpx;
	}

	.top_info {
		width: 30%;
		text-align: center;
		height: 65rpx;
		line-height: 65rpx;
		margin-top: 25rpx;
		margin-right: 25rpx;
		background-color: #EAEAEA;
		color: #6F6F6F;
		border-radius: 35rpx;
		font-size: 26rpx;
	}

	.top_check {
		background-color: #FEE9E8;
		border: 1rpx solid #f44b44;
		color: #f44b44;
		height: 64rpx;
		line-height: 64rpx;
	}
</style>